package com.qingcheng.dao;

import com.qingcheng.pojo.system.Resource;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface ResourceMapper extends Mapper<Resource> {

    @Select("SELECT id,`res_key` AS resKey ,`res_name` AS resName, `parent_id` AS parentId FROM `tb_resource` WHERE id IN (SELECT `resource_id` AS id FROM `tb_role_resource` WHERE `role_id`= #{id})")
    public List<Resource> findByRoleId(@Param("id") Integer id);

    /**
     * 根据用户名查询资源权限列表
     */
    @Select("SELECT res_key FROM tb_resource WHERE id IN ( " +
            "SELECT resource_id FROM tb_role_resource WHERE role_id IN ( " +
            "SELECT role_id FROM tb_admin_role WHERE admin_id IN ( " +
            "SELECT id FROM tb_admin WHERE login_name=#{loginName} " +
            ") " +
            ") " +
            ")")
    List<String> findResKeyByLoginName(@Param("loginName") String loginName);
}
